package com.meepo.basic.nightmode

import android.content.Context
import android.content.res.Configuration
import android.content.res.Configuration.UI_MODE_NIGHT_YES
import androidx.appcompat.app.AppCompatDelegate
import com.meepo.basic.nightmode.NightMode.NIGHT_MODE_FOLLOW_SYSTEM
import com.meepo.basic.nightmode.NightMode.NIGHT_MODE_NIGHT
import com.meepo.basic.nightmode.NightMode.NIGHT_MODE_NORMAL

/**
 * @author
 *
 * @date  2020/11/2 10:40 PM
 * @version 1.0
 */
object NightModeHelper {

    fun switchMode(delegate: AppCompatDelegate, mode: String) {
//        delegate.localNightMode = mapTo(mode)
//        initNighMode(mode)
    }

    fun isDarkMode(context: Context): Boolean {
        val mode = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
        return mode == UI_MODE_NIGHT_YES
    }


    fun initNighMode(mode: String) {
        // activity 重绘
//        AppCompatDelegate.setDefaultNightMode(mapTo(mode))
    }

    private fun mapTo(mode: String): Int {
        return when (mode) {
            NIGHT_MODE_NIGHT -> {
                AppCompatDelegate.MODE_NIGHT_YES
            }
            NIGHT_MODE_NORMAL -> {
                AppCompatDelegate.MODE_NIGHT_NO
            }
            NIGHT_MODE_FOLLOW_SYSTEM -> {
                AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
            }
            else -> {
                AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY
            }
        }
    }
}